package com.deliveryservicesystem.model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 * File Name: Driver.java
 * Version:
 * Description:
 * Package: com.deliveryservicesystem.model.newpackage
 * Author: Lance
 * Date: Jun 24, 2012
 * Editor:
 */
@Entity
@Table(name = "DRIVER")
@XmlRootElement
@NamedQueries(
{
    @NamedQuery(name = "Driver.findAll", query = "SELECT d FROM Driver d"),
    @NamedQuery(name = "Driver.findByDriverNo", query = "SELECT d FROM Driver d WHERE d.driverNo = :driverNo"),
    @NamedQuery(name = "Driver.findByFirstName", query = "SELECT d FROM Driver d WHERE d.firstName = :firstName"),
    @NamedQuery(name = "Driver.findByLastName", query = "SELECT d FROM Driver d WHERE d.lastName = :lastName"),
    @NamedQuery(name = "Driver.findByContactNo", query = "SELECT d FROM Driver d WHERE d.contactNo = :contactNo"),
    @NamedQuery(name = "Driver.findByAddress", query = "SELECT d FROM Driver d WHERE d.address = :address"),
    @NamedQuery(name = "Driver.findByVehicleRegistration", query = "SELECT d FROM Driver d WHERE d.vehicleRegistration = :vehicleRegistration")
})
public class Driver implements Serializable
{

    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name = "SEQ_DRIVER_NO", sequenceName = "SEQ_DRIVER_NO")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_DRIVER_NO")
    @Basic(optional = false)
    @Column(name = "DRIVER_NO")
    private Integer driverNo;
    @Basic(optional = false)
    @Column(name = "FIRST_NAME")
    private String firstName;
    @Basic(optional = false)
    @Column(name = "LAST_NAME")
    private String lastName;
    @Column(name = "CONTACT_NO")
    private String contactNo;
    @Basic(optional = false)
    @Column(name = "ADDRESS")
    private String address;
    @Column(name = "VEHICLE_REGISTRATION")
    private String vehicleRegistration;
    @OneToMany(mappedBy = "driverNo")
    private List<Delivery> deliveryList;

    public Driver()
    {
    }

    public Driver(Integer driverNo)
    {
        this.driverNo = driverNo;
    }

    public Driver(Integer driverNo, String firstName, String lastName, String address)
    {
        this.driverNo = driverNo;
        this.firstName = firstName;
        this.lastName = lastName;
        this.address = address;
    }

    public Integer getDriverNo()
    {
        return driverNo;
    }

    public void setDriverNo(Integer driverNo)
    {
        this.driverNo = driverNo;
    }

    public String getFirstName()
    {
        return firstName;
    }

    public void setFirstName(String firstName)
    {
        this.firstName = firstName;
    }

    public String getLastName()
    {
        return lastName;
    }

    public void setLastName(String lastName)
    {
        this.lastName = lastName;
    }

    public String getContactNo()
    {
        return contactNo;
    }

    public void setContactNo(String contactNo)
    {
        this.contactNo = contactNo;
    }

    public String getAddress()
    {
        return address;
    }

    public void setAddress(String address)
    {
        this.address = address;
    }

    public String getVehicleRegistration()
    {
        return vehicleRegistration;
    }

    public void setVehicleRegistration(String vehicleRegistration)
    {
        this.vehicleRegistration = vehicleRegistration;
    }

    @XmlTransient
    public List<Delivery> getDeliveryList()
    {
        return deliveryList;
    }

    public void setDeliveryList(List<Delivery> deliveryList)
    {
        this.deliveryList = deliveryList;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (driverNo != null ? driverNo.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Driver))
        {
            return false;
        }
        Driver other = (Driver) object;
        if ((this.driverNo == null && other.driverNo != null) || (this.driverNo != null && !this.driverNo.equals(other.driverNo)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "\nDriver Number: " + driverNo
                + "\nFirst Name: " + firstName
                + "\nLast Name: " + lastName
                + "\nContact Number: " + contactNo
                + "\nAddress: " + address
                + "\nVehicle Registration: " + vehicleRegistration;
    }
}
